package com.etc.controller;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;

import com.etc.entity.User;

@Controller
public class UserController {

	@GetMapping("userlogin")
	public String login(@Valid User user,BindingResult result,org.springframework.ui.Model model)
	{
		//如果校验中存在Error
		if (result.hasErrors()) {
			//得到error的具体信息
			String msg=result.getFieldError().getDefaultMessage();
			//将信息存储到model中
			model.addAttribute("msg", msg);
			//转发到特定的某个页面
			return "forward:error.jsp";
		}
		return "redirect:/";
	}
}
